package com.atcx.controller;


import com.atcx.pojo.Classes;
import com.atcx.service.ClassesService;
import com.atcx.util.PageResult;
import com.atcx.util.QueryPageBean;
import com.atcx.util.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author pangShu
 * @since 2022-03-23
 */
@RestController
@RequestMapping("/classes")
public class ClassesController {


    private Result result;
    @Resource
    private ClassesService classesService;
    //添加
    @RequestMapping("addClasses")
    public Result addClasses(@RequestBody Classes classes){
        int i = classesService.addClasses(classes);
        if (i>0){
            result = new Result(true,"添加班级信息成功");
        }else {
            result = new Result(false,"添加班级信息失败");
        }
        return result;
    }
    //修改
    @RequestMapping("updateClasses")
    public Result updateClasses(@RequestBody Classes classes){
        int i = classesService.updateClasses(classes);
        if (i>0){
            result = new Result(true,"修改班级信息成功");
        }else {
            result = new Result(false,"修改班级信息失败");
        }
        return result;
    }
    //删除
    @RequestMapping("deleteClasses")
    public Result deleteClasses(int id){
        int i = classesService.deleteClasses(id);
        if (i>0){
            result = new Result(true,"删除班级信息成功");
        }else {
            result = new Result(false,"删除班级信息失败,请先删除关联信息");
        }
        return result;
    }
    //查找
    @RequestMapping("findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean){
        PageResult page = classesService.findByPage(queryPageBean);
        if (page != null){
            result = new Result(true,"查询班级信息成功",page);
        }else {
            result = new Result(false,"查询班级信息失败");
        }
        return result;
    }
    //报表信息
    @RequestMapping("getTotal")
    public Result getTotal(){
        Map<String, Object> map = classesService.getTotal();
        if (map!=null){
            result = new Result(true,"查询成绩成功",map);

        }else {
            result = new Result(false,"查询信息失败");
        }
        return result;
    }
    //查询所有班级信息
    @RequestMapping("getList")
    public Result getList(){
        List<Classes> list = classesService.getList();
        if (list!=null){
            result = new Result(true,"查询班级信息成功",list);
        }
        for (Classes classes : list) {
            System.out.println(classes);
        }
       return result;
    }


}

